package com.rds.web.controller.pms;

import com.rds.common.annotation.Log;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.system.domain.RdaSubcommandRel;
import com.rds.system.service.IRdaSubcommandRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * menu关系Controller
 *
 * @author rds
 * @date 2021-05-26
 */
@RestController
@RequestMapping("/pms/subcommand")
public class RdaSubcommandRelController extends BaseController
{
    @Autowired
    private IRdaSubcommandRelService rdaSubcommandRelService;

    /**
     * 查询menu关系列表
     */
//    @PreAuthorize("@ss.hasPermi('pms:toolbar:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaSubcommandRel rdaSubcommandRel)
    {
        startPage();
        List<RdaSubcommandRel> list = rdaSubcommandRelService.selectRdaSubcommandRelByFromId(rdaSubcommandRel);
        return getDataTable(list);
    }

    /**
     * 导出menu关系列表
     */
    @PreAuthorize("@ss.hasPermi('pms:subcommand:export')")
    @Log(title = "menu关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaSubcommandRel rdaSubcommandRel)
    {
        List<RdaSubcommandRel> list = rdaSubcommandRelService.selectRdaSubcommandRelList(rdaSubcommandRel);
        ExcelUtil<RdaSubcommandRel> util = new ExcelUtil<RdaSubcommandRel>(RdaSubcommandRel.class);
        return util.exportExcel(list, "rel");
    }

    /**
     * 获取menu关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:subcommand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaSubcommandRelService.selectRdaSubcommandRelById(id));
    }

    /**
     * 新增menu关系
     */
    @PreAuthorize("@ss.hasPermi('pms:subcommand:add')")
    @Log(title = "menu关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaSubcommandRel rdaSubcommandRel)
    {
        return toAjax(rdaSubcommandRelService.insertRdaSubcommandRel(rdaSubcommandRel));
    }

    /**
     * 修改menu关系
     */
    @PreAuthorize("@ss.hasPermi('pms:subcommand:edit')")
    @Log(title = "menu关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaSubcommandRel rdaSubcommandRel)
    {
        return toAjax(rdaSubcommandRelService.updateRdaSubcommandRel(rdaSubcommandRel));
    }

    /**
     * 删除menu关系
     */
    @PreAuthorize("@ss.hasPermi('pms:subcommand:remove')")
    @Log(title = "menu关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaSubcommandRelService.deleteRdaSubcommandRelByIds(ids));
    }

}
